package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.DeviceVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface DeviceMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Device record);

    int insertSelective(Device record);

    Device selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Device record);

    int updateByPrimaryKey(Device record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table device
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<Device> list);

    /**
     * 根据设备名字查找数据库设备的数量
     * @param deviceName
     * @return
     */
    @Select("select count(1) from device where device_name = #{deviceName}")
    Long countByDeviceName(String deviceName);

    /**
     * 根据条件查询设备列表数据
     * @param devicePageQueryDto
     * @return
     */
    Page<DeviceVo> selectByPage(DevicePageQueryDto devicePageQueryDto);

    /**
     * 根据设备id查询设备对象
     * @param iotId
     * @return
     */
    DeviceVo selectByIotId(String iotId);

    /**
     * 按天获取每小时的心率统计数据
     * @param iotId
     * @param functionId
     * @param minCreateTime
     * @param maxCreateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByDay(
            @Param("iotId") String iotId, @Param("functionId") String functionId,
            @Param("minCreateTime") LocalDateTime minCreateTime, @Param("maxCreateTime") LocalDateTime maxCreateTime);


    /**
     * 按周获取每天的心率统计数据
     * @param iotId
     * @param functionId
     * @param minCreateTime
     * @param maxCreateTime
     * @return
     */
    List<DeviceDataGraphVo> queryDeviceDataListByWeek(
            @Param("iotId") String iotId, @Param("functionId") String functionId,
            @Param("minCreateTime") LocalDateTime minCreateTime, @Param("maxCreateTime") LocalDateTime maxCreateTime);


    List<Long> selectNursingIdsByIotIdWithElder(String iotId);

    List<Long> selectNursingIdsByIotIdWithBed(String iotId);
}